package be.dch.gui.panels;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JColorChooser;
import javax.swing.JPanel;

import be.dch.gui.components.JImagePanel;
import be.dch.gui.components.JRasterPanel;

public class TypEditorImagePanel extends JPanel {

    private static final long serialVersionUID = 1571684579240495399L;

    private static final int RASTER_TILES = 15;

    private final transient JColorChooser colorChooser;
    private final transient JRasterPanel raster;
    private final transient JImagePanel imagePreview;

    public TypEditorImagePanel() {
	super();
	// String columnSpecs = "1dlu:grow,pref,1dlu:grow";
	// String rowSpecs = "3dlu,pref,3dlu,pref:grow";
	//
	// FormLayout layout = new FormLayout(columnSpecs, rowSpecs);
	// CellConstraints cc = new CellConstraints();
	// PanelBuilder builder = new PanelBuilder(layout);

	this.colorChooser = new JColorChooser();
	this.colorChooser.setPreviewPanel(new JPanel());
	// builder.add(colorChooser, cc.rchw(7, 2, 1, 6));

	this.raster = new JRasterPanel(TypEditorImagePanel.RASTER_TILES);
	this.raster.addMouseListener(new MouseAdapter() {
	    @Override
	    public void mousePressed(final MouseEvent event) {
		TypEditorImagePanel.this.raster.setColorForLocation(event.getX(), event.getY(), TypEditorImagePanel.this.colorChooser.getColor());
		TypEditorImagePanel.this.raster.repaint();
		TypEditorImagePanel.this.imagePreview.setImage(TypEditorImagePanel.this.raster.getPixels());
	    }

	});
	// builder.add(raster, cc.rchw(5, 2, 1, 6));

	this.imagePreview = new JImagePanel(this.raster.getPixels());
	// builder.add(imagePreview, cc.rchw(2, 2, 1, 1));
    }

}
